<?php

namespace App\Http\Controllers\Api;

use App\Models\Card;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB;

class CardController extends AuthController
{

    private $uid = '';


    public function __construct()
    {
        $this->uid = auth('api')->id();
    }

    //课时卡列表
    public function cardList(){
         $card = new Card();
        $res = $card->getCardList($this->uid);
         return self::returnAjax(['list'=>$res], 200, "课时卡列表");
    }

    public function me()
    {
        return response()->json(auth('api')->user());
    }

    //课时卡详情
    public function getDetailCard(Request $request)
    {
        $id = $request['id'];
        if (!$this->uid){
            return parent::ajaxReturn(202, new \stdClass(), '用户身份失效');
        }
//        if (Cache::has('DetailCard' . $id)) {
//            $res = Cache::get('DetailCard' . $id);
//            return self::returnAjax($res, 200, "课时卡详情");
//        }
        $res = Card::getDetailCard($id,$this->uid) ?? '';
//        if ($res){
//            Cache::add('DetailCard' . $id, $res,1440);
//        }
        return self::returnAjax($res, 200, "课时卡详情");
    }
}
